package cn.wolfcode.web.controller;

import cn.wolfcode.service.IPasswordManagementService;
import cn.wolfcode.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

// 密码管理控制器
@Controller
@RequestMapping("/passwordManagement")
public class PasswordManagementController {
    @Autowired
    private IPasswordManagementService passwordManagementService;
    // 重置密码页面
    @RequestMapping("/reset")
    @ResponseBody // 只响应结果不找视图
    public JsonResult Reset(String newPassword, Long id){
        if (newPassword == null || newPassword.equals("")) {
            return new JsonResult(false,"请输入新密码");
        }
        // 数据传给业务层处理
        JsonResult jsonResult = passwordManagementService.Reset(newPassword,id);
        return jsonResult;

    }

    // 修改密码页面
    @RequestMapping("/update")
    @ResponseBody // 只响应结果不找视图
    public JsonResult update(String oldPassword , String newPassword) {
        JsonResult js = new JsonResult();
        js.setSuccess(false);
            if (oldPassword == null || oldPassword.equals("")) {
                js.setMsg("请输入旧密码");
                return js;
            } else if (newPassword == null || newPassword.equals("")) {
                js.setMsg("请输入新密码");
                return js;
            }
            return passwordManagementService.update(oldPassword, newPassword);
    }

}
